
/*
'===============================================================================
'  Generated From - BLL_Component_Partial_Core.vbgen
'  
'  This object is partial class component representing a table in a database. It
'  contains core data access methods. Other partial classes should be used for 
'  implementing custom business logic. This class can be regenerated many times.
'  
'  Do not write custom business logic in this class as it will be overwritten 
'  next time the class is generated.
'
'  Version: 1.0
'  Date:	30/01/06
'  Summary: SelectOne, SelectAll, SelectAllWForeignKey, Insert, Update, Delete,
'  			DeleteAllWForeignKey, class for sorting.
'===============================================================================
*/
using System;
using System.ComponentModel;
using System.Data;
using System.Collections.Generic;

namespace PlacementManager
{
    [DataObjectAttribute]
	public partial class ContactNumberTypeComponent
    {
        
		/// <summary>
        /// Default constructor.
        /// </summary>
		public ContactNumberTypeComponent()
        {

        }
		
		/// <summary>
        /// Selects one record from the database table using the primary key.
        /// </summary>
        /// <returns>An object of a type representing a row in the database table.</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
		public ContactNumberType SelectOne(int ContactNumberTypeId)
        {  
			PlacementManager.DAL.ContactNumberType_DAL o = new PlacementManager.DAL.ContactNumberType_DAL();
			o.ContactNumberTypeId = ContactNumberTypeId;
			DataTable dt = o.SelectOne().Tables[0];
			
			if (dt.Rows.Count > 0)
            {
                DataRow row = dt.Rows[0];
				PlacementManager.ContactNumberType ContactNumberTypeToReturn = new PlacementManager.ContactNumberType((int)row["ContactNumberTypeId"], (string)row["ContactNumberTypeName"]);
				return ContactNumberTypeToReturn;
			}
			else
			{
				PlacementManager.ContactNumberType ContactNumberTypeToReturnEmpty = new PlacementManager.ContactNumberType();
                return ContactNumberTypeToReturnEmpty;
			}
        }
		
		/// <summary>
        /// Selects all records from the database table.
        /// </summary>
        /// <returns>A collection of objects of a type representing a row in the database table.</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
		public List<ContactNumberType> SelectAll(string sortExpression)
        {
            List<ContactNumberType> listContactNumberType = new List<ContactNumberType>();
            PlacementManager.DAL.ContactNumberType_DAL o = new PlacementManager.DAL.ContactNumberType_DAL();

            DataSet ds = o.SelectAll();

            foreach (DataRow row in ds.Tables[0].Rows)
            {
                listContactNumberType.Add(new ContactNumberType((int)row["ContactNumberTypeId"], (string)row["ContactNumberTypeName"]));
            }
			
			if (sortExpression == string.Empty)
            {
                sortExpression = "DateCreated desc";
            }

            listContactNumberType.Sort(new ContactNumberTypeComparer(sortExpression));
            return listContactNumberType;
        }
	
		/// <summary>
        /// Selects all records from the database table based on a foreign key.
        /// </summary>
        /// <returns>A collection of objects of a type representing a row in the database table.</returns>


		/// <summary>
        /// Inserts a new row into the datatable.
        /// </summary>
        /// <param name="o">An object of a datatype representing a row in the database table.</param>
        /// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Insert, true)]
		public int Insert(ContactNumberType o)
        {	
            PlacementManager.DAL.ContactNumberType_DAL oContactNumberType = new PlacementManager.DAL.ContactNumberType_DAL();
			oContactNumberType.ContactNumberTypeName = o.ContactNumberTypeName;

            return oContactNumberType.Insert();
        }
		
		/// <summary>
        /// Inserts a new row into the datatable by passing parameters represneting each column.
        /// </summary>
        /// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Insert, true)]
		public int Insert(string ContactNumberTypeName)
        {
            PlacementManager.DAL.ContactNumberType_DAL oContactNumberType = new PlacementManager.DAL.ContactNumberType_DAL();

			oContactNumberType.ContactNumberTypeName = ContactNumberTypeName;

            return oContactNumberType.Insert();
        }

		/// <summary>
        /// Updates a row in the database table based on the primary key.
        /// </summary>
        /// <param name="o">An object of a datatype representing a row in the database table.</param>
        /// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Update, true)]
		public bool Update(ContactNumberType o)
        {	
            PlacementManager.DAL.ContactNumberType_DAL oContactNumberType = new PlacementManager.DAL.ContactNumberType_DAL();
			oContactNumberType.ContactNumberTypeId = o.ContactNumberTypeId;
			oContactNumberType.ContactNumberTypeName = o.ContactNumberTypeName;

            return oContactNumberType.Update();
        }
		
		/// <summary>
        /// Updates a row in the database table based on the primary key by passing the values of each column as parameters.
        /// </summary>
        /// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Update, true)]
		public bool Update(int ContactNumberTypeId, string ContactNumberTypeName)
        {
            PlacementManager.DAL.ContactNumberType_DAL oContactNumberType = new PlacementManager.DAL.ContactNumberType_DAL();

			oContactNumberType.ContactNumberTypeId = ContactNumberTypeId;
			oContactNumberType.ContactNumberTypeName = ContactNumberTypeName;

            return oContactNumberType.Update();
        }
		
		/// <summary>
        /// Deletes one row in the database table.
        /// </summary>
        /// <param name="o">An object of a datatype representing a row in the database table.</param>
        /// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Delete, true)]
		public bool Delete(ContactNumberType o)
        {
            PlacementManager.DAL.ContactNumberType_DAL oContactNumberType_DAL = new PlacementManager.DAL.ContactNumberType_DAL();
            oContactNumberType_DAL.ContactNumberTypeId = o.ContactNumberTypeId;
            return oContactNumberType_DAL.Delete();
        }
		
		/// <summary>
        /// Deletes one row in the database table by passing the primary key.
        /// </summary>
        /// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Delete, true)]
		public bool Delete(int ContactNumberTypeId)
        {
            PlacementManager.DAL.ContactNumberType_DAL oContactNumberType_DAL = new PlacementManager.DAL.ContactNumberType_DAL();
            oContactNumberType_DAL.ContactNumberTypeId = ContactNumberTypeId;
            return oContactNumberType_DAL.Delete();
        }
		
		/// <summary>
		/// Deletes all rows in a table based on a foreign key.
		/// </summary>
		/// <returns>Boolean</returns>

	}
	
	public class ContactNumberTypeComparer : IComparer<ContactNumberType>
    {
        private string _sortColumn;
        private bool _reverse;

        public ContactNumberTypeComparer(string sortExpression)
        {
            _reverse = sortExpression.ToLowerInvariant().EndsWith(" desc");
            if (_reverse)
            {
                _sortColumn = sortExpression.Substring(0, sortExpression.Length - 5);
            }
            else
            {
                _sortColumn = sortExpression;
            }
        }

        public int Compare(ContactNumberType a, ContactNumberType b)
        {
            int retVal = 0;
            switch (_sortColumn)
            {
				case "ContactNumberTypeId":
					retVal = String.Compare(a.ContactNumberTypeId.ToString(), b.ContactNumberTypeId.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "ContactNumberTypeName":
					retVal = String.Compare(a.ContactNumberTypeName.ToString(), b.ContactNumberTypeName.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;

            }
            return (retVal * (_reverse ? -1 : 1));
        }
    }
}
